package com.ggsound.bluetoothbox.ui.adapter;

import android.graphics.Color;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.text.TextUtils;

import com.ggsound.bluetoothbox.R;
import com.ggsound.bluetoothbox.bean.Music;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * @author 尹晓童
 *         邮箱：yinxtno1@yeah.net
 *         时间：2017/11/28
 *         作用：蓝牙 模式音乐列表界面
 */

public class BluetoothMusicAdapter extends BaseQuickAdapter<Music, BaseViewHolder> {
    private int selectedIndex = -1;        //记录当前选中的条目索引

    public void setSelectedIndex(int position) {
        if (selectedIndex!=-1){
            notifyItemChanged(selectedIndex);
        }
        this.selectedIndex = position;
        notifyItemChanged(position);
    }
    public BluetoothMusicAdapter(@Nullable List<Music> data) {
        super(R.layout.item_music, data);
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void convert(BaseViewHolder holder, Music item) {

        holder.setText(R.id.tv_name, TextUtils.isEmpty(item.getAlbum()) ? "unknown" : item.getArtist());
        holder.setText(R.id.tv_info, item.getFileName());
        if (selectedIndex == holder.getPosition()) {
             //选中状态
             holder.setTextColor(R.id.tv_name, mContext.getColor(R.color.list_select));
            holder.setTextColor(R.id.tv_info,mContext.getColor(R.color.list_select));
        } else {                                                            //非选中状态
            holder.setTextColor(R.id.tv_name,Color.WHITE);
            holder.setTextColor(R.id.tv_info,Color.WHITE);
        }

    }
}
